﻿//using System;
//using System.Text;
//using System.Collections.Generic;
//using System.Linq;
//using MvcCms.Web.Code;
//using MvcCms.Service.Code.Membership;
//using NUnit.Framework;
//using Rhino.Mocks;
//using MvcContrib.TestHelper;
//using MvcCms.Web.Controllers;
//using MvcCms.Service;
//using MvcCms.Service.Cache;
//using System.Web.Mvc;
//using MvcCms.Data;
//using System.Web;
//using System.Web.Security;

//namespace MvcCms.Web.Tests.Controllers
//{
//    [TestFixture]
//  public  class AccountControllerTests
//  {
//      private  IAccountService _accountService;
//      private  IMiscService _miscService;
//      TestControllerBuilder _builder;
//      AccountController _controller;
//      public IFormsAuthentication FormsAuth ;
//      Portal currentPortal;
//      public ICacheService cacheService;

//      [TestFixtureSetUp]
//      public void Setup()
//      {     
//          cacheService = MockRepository.GenerateStub<ICacheService>();
//          _miscService = MockRepository.GenerateStub<IMiscService>();
//          _accountService = MockRepository.GenerateStub<IAccountService>();
//          FormsAuth = MockRepository.GenerateStub<IFormsAuthentication>();

//          currentPortal = new Portal { AdminEmail = "", AllowOpenIdRegistration = false, AllowPageWikiHtmlSwitch = false, ContentCategories = null, ContentPages = null, DisplayName = "test" };
//          cacheService.Expect(cr => cr.GetCurrentPortal()).Return(currentPortal);
//          _builder = new TestControllerBuilder();
//          _controller = _builder.CreateController<AccountController>(cacheService, FormsAuth, _accountService, _miscService);
            


//      }
//      [Test]
//      public void TestLogOnShouldRenderViewIndex()
//      {
         
         
//          ActionResult result = _controller.LogOn();
//          Assert.AreSame(_controller.ViewData["SiteName"], currentPortal.DisplayName);
//          Assert.AreEqual(_controller.ViewData["OpenId"], string.Empty);
//          Assert.AreSame(_controller.ViewData["PageTitle"], "Login");
//          Assert.AreEqual(_controller.ViewData["AllowOpenIdRegistration"], currentPortal.AllowOpenIdRegistration);
//          Assert.AreSame(_controller.ViewData["referer"], string.Empty);
          
//      }


//      [Test]
//      public void TestLogOnShouldSignInUserAndRenderViewIndex()
//      {
//          string username = "username";
//          string urlToRedirect = "testurl";
//          string password="password";
//          Membership.Expect(cr => cr.ValidateUser(username,password)).Return(true);
//          ActionResult result = _controller.LogOn(username, password, true, urlToRedirect);

//            FormsAuth.AssertWasCalled(x => x.SignIn(username,true));

//            Assert.AreSame(_controller.ViewData["referer"], urlToRedirect);
//          Assert.AreEqual(_controller.ViewData["OpenId"], string.Empty);
     
//          Assert.AreEqual(_controller.ViewData["AllowOpenIdRegistration"], currentPortal.AllowOpenIdRegistration);
//          result.AssertHttpRedirect().ToUrl(urlToRedirect);
//      }

//      [Test]
//      public void TestFailedLogOnAddsErrorsToModelStateAndRendersCorrectViewIndex()
//      {
//          string username = string.Empty;
//          string password = string.Empty;
//          MembershipService.Expect(cr => cr.ValidateUser(username, password)).Return(false);
//          ActionResult result = _controller.LogOn(username, password, true, "testurl");

//          FormsAuth.AssertWasNotCalled(x => x.SignIn(username, true));

//          Assert.AreSame(_controller.ViewData["SiteName"], currentPortal.DisplayName);
//          Assert.AreEqual(_controller.ViewData["PageTitle"], "Login");
//         Assert.AreEqual( _controller.ModelState.Count,3);
//          result.AssertViewRendered().ForView(string.Empty);
//      }

//      [Test]
//      public void TestCorrectRegistrationDetailsCreatesMembershipStatusAndRendersCorrectViewIndex()
//      {
//          string username = "username";
//          string password = "password";
//          string email = "password";
//          MembershipCreateStatus createStaus = MembershipCreateStatus.Success;
//          MembershipService.Expect(cr => cr.CreateUser(username, password, email)).Return(createStaus);
         
//          User user = new User { UserName = username, Password = password, Email = email };
//          _accountService.Expect(cr => cr.GetUser(username)).Return(user);

//          //we addeda a nobot key to the registration method, this should redirect to to the portal url
//          ActionResult result = _controller.Register(username, email, password, password, "testurl", "");

//          FormsAuth.AssertWasCalled(x => x.SignIn(username, false));

//          Assert.AreSame(_controller.ViewData["AllowOpenIdRegistration"], currentPortal.AllowOpenIdRegistration);
//          Assert.AreEqual(_controller.ViewData["OpenId"], string.Empty);
//          Assert.AreEqual(_controller.ViewData["message"], string.Empty);
//          Assert.AreEqual(_controller.ViewData["resourcebody"], string.Empty);
//          Assert.AreEqual(_controller.ViewData["referer"], "testurl");
//          result.AssertActionRedirect().ToAction<AccountController>(c => c.UserProfile("","","","","",DateTime.Now,"","",1,"","","","","","",1,"","","",""));
         
//      }


//    }
//}
